package com.engine.qz.transmethod;

import cn.hutool.core.util.ObjectUtil;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;

public class FieldTransMethod {
    private static RecordSet rs = new RecordSet();

    public static String getLastname(String param) {
        String sql = "select lastname from hrmresource where id =?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("lastname");
        }
        return param;
    }

    //分部
    public static String getSubcompany(String param) {
        String sql = "select subcompanyname from HrmSubCompany where id =?";
        if (param.contains(">")) {
            String result = "";
            String[] split = param.split(">");
            for (String s : split) {
                rs.executeQuery(sql, s);
                if (rs.next()) {
                    result += rs.getString("subcompanyname") + ">";
                }
            }
            return result.substring(0, result.lastIndexOf(">"));
        } else {
            rs.executeQuery(sql, param);
            if (rs.next()) {
                return rs.getString("subcompanyname");
            }
        }
        return param;
    }

    //部门
    public static String getDept(String param) {
        String sql = " select departmentname from HrmDepartment where id =?";
        if (param.contains(">")) {
            String result = "";
            String[] split = param.split(">");
            for (String s : split) {
                rs.executeQuery(sql, s);
                if (rs.next()) {
                    result += rs.getString("departmentname") + ">";
                }
            }
            return result.substring(0, result.lastIndexOf(">"));
        } else {
            rs.executeQuery(sql, param);
            if (rs.next()) {
                return rs.getString("departmentname");
            }
        }
        return param;
    }

    public static String getJobtitle(String param) {
        String sql = "select gwmc from uf_JCL_GWGL where id=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("gwmc");
        }
        return param;
    }

    /**
     * 岗位等级
     *
     * @param param
     * @return
     */
    public static String getJobLevel(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=21 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //员工职级	YGZJ
    public static String getJobRank(String param) {
        String sql = "select zjmc from uf_zjfa_dt1 where id=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("zjmc");
        }
        return param;
    }

    //SRRQLX生日日期类型
    public static String getBirthDayType(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=62 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //学历类别
    public static String getXllb(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=58 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //STATUS员工状态
    public static String getStatus(String param) {
        String sql = "SELECT SELECTNAME FROM hrm_selectitem \nWHERE fieldid = (SELECT fieldid FROM hrm_formfield WHERE fieldname = 'status') AND SELECTVALUE=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    public static String getUseKind(String param) {
        String sql = "select name from HrmUseKind where id=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("name");
        }
        return param;
    }

    public static String getSex(String param) {
        String sql = "SELECT SELECTNAME FROM hrm_selectitem \nWHERE fieldid = (SELECT fieldid FROM hrm_formfield WHERE fieldname = 'sex') AND SELECTVALUE=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //EDUCATIONLEVEL第一学历
    public static String getEducation(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=66 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }


    public static String getMaritalstatus(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "SELECT SELECTNAME FROM hrm_selectitem WHERE fieldid = (SELECT fieldid FROM hrm_formfield WHERE fieldname = 'maritalstatus') AND SELECTVALUE=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    // 是否干部 SFGB
    public static String getIsCadre(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=29 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    // 干部情形 GBQX
    public static String getCadreType(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=40 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    public static String getWDD(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=35 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    public static String getJRZCSD(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=37 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    public static String getYDYYD(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=38 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //合同主体HTGSMC
    public static String getContractType(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select ztmc from uf_htzt where id=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("ztmc");
        }
        return param;
    }

    public static String getDJLS(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select lastname from HRMRESOURCE where id=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("lastname");
        }
        return param;
    }

    public static String getZPLY(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=42 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    /**
     * 是否二次入职
     *
     * @param param
     * @return
     */
    public static String getSFECRZ(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = "select selectname from cus_selectitem where fieldid=60 AND selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //lizhiyewuleixing 离职类型
    public static String getLeaveType(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = " select selectname from workflow_SelectItem where fieldid='11399' and selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //离职详细原因（直接上级）lzxxyyzjsj
    public static String getlzxxyyzjsj(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = " select selectname from workflow_SelectItem where fieldid='15060' and selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //离职详细原因（公司原因）lzxxyygsyy
    public static String getlzxxyygsyy(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = " select selectname from workflow_SelectItem where fieldid='15061' and selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //离职详细原因（员工原因）lzxxyyygyy
    public static String getlzxxyyygyy(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = " select selectname from workflow_SelectItem where fieldid='15062' and selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //ywxz 有无薪资
    public static String getywxz(String param) {
        if (StringUtils.isEmpty(param)) {
            return param;
        }
        String sql = " select selectname from workflow_SelectItem where fieldid='12963' and selectvalue=?";
        rs.executeQuery(sql, param);
        if (rs.next()) {
            return rs.getString("selectname");
        }
        return param;
    }

    //是否考核期
    public static String getSfkhq(String param) {
        if (ObjectUtil.equal(param, "0")) {
            return "是";
        } else {
            return "否";
        }
    }

}
